package com.anxin.controller;

import com.anxin.entity.Orders;
import com.anxin.service.OrdersService;
import com.anxin.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Tag(name = "订单管理")
@RestController
@RequestMapping("/api/orders")
public class OrdersController extends BaseController {
    @Autowired
    private OrdersService ordersService;

    @Operation(summary = "根据ID获取订单")
    @GetMapping("/{id}")
    public Result<Orders> getById(@Parameter(description = "订单ID") @PathVariable String id) {
        return Result.success(ordersService.getById(id));
    }

    @Operation(summary = "获取订单列表")
    @GetMapping("/list")
    public Result<List<Orders>> list() {
        return Result.success(ordersService.list());
    }

    @Operation(summary = "保存或更新订单")
    @PostMapping("/save")
    public Result<Boolean> save(@RequestBody Orders orders) {
        return Result.success(ordersService.saveOrUpdate(orders));
    }

    @Operation(summary = "删除订单")
    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@Parameter(description = "订单ID") @PathVariable String id) {
        return Result.success(ordersService.removeById(id));
    }
} 